﻿Imports DTO
Imports System.Linq


Public Class KhoiDAO

    Public Function getLevel_DAO()
        Dim list As List(Of KhoiDTO) = New List(Of KhoiDTO)

        Dim context As DataproviderDataContext = New DataproviderDataContext()

        Dim listKhoi = From khoi In context.Khois
                       Select khoi

        For Each value As Khoi In listKhoi
            Dim entity As KhoiDTO = New KhoiDTO()
            entity.MaKhoi = value.MaK
            entity.TenKhoi = value.TenKhoi

            list.Add(entity)
        Next
        Return list
    End Function

    Public Function getLevelFollowClass_DAO(ByVal mal As String)
        Dim list As List(Of KhoiDTO) = New List(Of KhoiDTO)

        Dim context As DataproviderDataContext = New DataproviderDataContext()

        Dim listk = From khoi In context.Khois
                    Join lop In context.Lops On khoi.MaK Equals lop.MaKhoi
                    Where lop.MaL.Contains(mal)
                    Select khoi

        For Each value In listk
            Dim entity As KhoiDTO = New KhoiDTO()
            entity.MaKhoi = value.MaK
            entity.TenKhoi = value.TenKhoi

            list.Add(entity)
        Next
        Return list
    End Function

    Public Function getLevelFollowId_DAO(ByVal id As Integer) As Integer
        'Dim list As List(Of KhoiDTO) = New List(Of KhoiDTO)
        Dim lv As Integer
        Dim context As DataproviderDataContext = New DataproviderDataContext()

        Dim listKhoi = From khoi In context.Khois
                       Where khoi.MaK = id
                       Select khoi

        For Each value As Khoi In listKhoi
            'Dim entity As KhoiDTO = New KhoiDTO()
            ''entity.MaKhoi = value.MaK
            'entity.TenKhoi = value.TenKhoi

            ''List.Add(entity)
            lv = value.TenKhoi
        Next
        'Return List
        Return lv
    End Function
End Class
